"""
@author: 江同学呀
@file:  shards_count.py
@date: 2025/3/15 12:51
@desc: 
    
"""
from typing import Dict

from espc.orm.model.base.base import _Base


class ShardsCount(_Base):
    """
    分片计数

    (object) Contains a count of shards used for the request.
    （对象）包含用于请求的分片计数。

    :param total:
        (integer) Total number of shards that require querying, including unallocated shards.
        （整数）需要查询的分片总数，包括未分配的分片。
    :param successful:
        (integer) Number of shards that executed the request successfully.
        （整数）成功执行请求的分片数。
    :param skipped:
        (integer) Number of shards that skipped the request because a lightweight check helped realize that no documents
        could possibly match on this shard. This typically happens when a search request includes a range filter and the
        shard only has values that fall outside of that range.
        （整数）由于轻量级检查帮助意识到此分片上不可能匹配任何文档而跳过请求的分片数。当搜索请求包含范围筛选条件，并且分片仅包含超出该范围的值时，
        通常会发生这种情况。
    :param failed:
        (integer) Number of shards that failed to execute the request. Note that shards that are not allocated will be
        considered neither successful nor failed. Having failed+successful less than total is thus an indication that
        some of the shards were not allocated.
        （整数）执行请求失败的分片数。请注意，未分配的分片将被视为既不成功也不失败。因此，如果 failed+successful 小于 total，则表示某些分片
        未分配。
    """

    def __init__(self, total: int = None, successful: int = None, failed: int = None, skipped: int = None):
        super().__init__()
        self.total: int = total
        self.successful: int = successful
        self.failed: int = failed
        self.skipped: int = skipped
        return

    def _build(self):
        _body: Dict[str, int] = {}
        if self.total is not None:
            _body["total"] = self.total
        if self.successful is not None:
            _body["successful"] = self.successful
        if self.failed is not None:
            _body["failed"] = self.failed
        if self.skipped is not None:
            _body["skipped"] = self.skipped
        return _body


